package com.hawkstar66.practice.funny.main;

import java.util.Scanner;

import com.hawkstar66.practice.funny.Executor;
import com.hawkstar66.practice.funny.commons.FunnyUtils;
import com.hawkstar66.practice.funny.commons.StringUtils;

public class FunnyMain {
	
	public static void main(String[] args) {
		StringBuffer selectorInfo = new StringBuffer();
		selectorInfo.append("请选择要执行的程序,输入程序名前的编号。").append(FunnyUtils.ENTER);
		
		FunnyFactory.init();
		
		Executor executor = null;
		String explain = null;
		for(int i=0;i<FunnyFactory.executors.size();i++) {
			executor = FunnyFactory.getInstance(i+1);
			if(null == executor) {
				continue;
			}
			explain = executor.getExecutorExplain();
			explain = StringUtils.trimToEmpty(explain);
			explain.replaceAll(FunnyUtils.ENTER, FunnyUtils.SEPARATOR_CONTENT);
			explain += FunnyUtils.ENTER;
			
			selectorInfo.append(i+1).append(FunnyUtils.SEPARATOR_EXECUTOR)
						.append(explain).append(FunnyUtils.ENTER);
		}
		
		Scanner input = new Scanner(System.in);
		
		int index = 1;
		int quit = 1;
		while(true) {
			System.out.println(selectorInfo);
			
			index = input.nextInt();
			executor = FunnyFactory.getInstance(index);
			
			System.out.println(executor.getStory());
			
			executor.execute(input);
			
			System.out.println("是否继续? 1.继续; 0.退出");
			quit = input.nextInt();
			if(1 == quit) {
				continue;
			}
			break;
		}
		
		
	}

}
